  

* This file uses the ANES cumulative file: https://electionstudies.org/data-center/anes-time-series-cumulative-data-file/

svyset [pw=VCF0009z]
gen year = VCF0004

*drop if year<1992

* Iygengar's measure for 2012
gen battleground = 0 if year==2012
replace battleground = 1 if VCF0901a == 12 & year==2012
replace battleground = 1 if VCF0901a == 37 & year==2012
replace battleground = 1 if VCF0901a == 51 & year==2012

gen battle = 0 if year == 2004 
replace battle = . if year!=2004
replace battle =1 if VCF0901a == 8 & year==2004 // Colorado, 
replace battle =1 if VCF0901a == 12 & year==2004 // Florida
replace battle =1 if VCF0901a == 19 & year==2004 // Iowa
replace battle =1 if VCF0901a == 26 & year==2004 // Michigan
replace battle =1 if VCF0901a == 27 & year==2004 // Minnesota
replace battle =1 if VCF0901a == 32 & year==2004 // Nevada
replace battle =1 if VCF0901a == 33 & year==2004 // New Hampshire
replace battle =1 if VCF0901a == 35 & year==2004 // New Mexico
replace battle =1 if VCF0901a == 39 & year==2004 // Ohio
replace battle =1 if VCF0901a == 41 & year==2004 // Oregon
replace battle =1 if VCF0901a == 42 & year==2004 // Pennsylvania
replace battle =1 if VCF0901a == 55 & year==2004 // Wisconsin





replace battle= 0 if year == 2008 
replace battle =1 if VCF0901a == 8 & year==2008 // Colorado, 
replace battle =1 if VCF0901a == 12 & year==2008 // Florida
replace battle =1 if VCF0901a == 26 & year==2008 // Michigan
replace battle =1 if VCF0901a == 29 & year==2008 // Missouri, 
replace battle =1 if VCF0901a == 32 & year==2008 // Nevada
replace battle =1 if VCF0901a == 33 & year==2008 // New Hampshire
replace battle =1 if VCF0901a == 35 & year==2008 // New Mexico
replace battle =1 if VCF0901a == 39 & year==2008 // Ohio
replace battle =1 if VCF0901a == 39 & year==2008 // Ohio
replace battle =1 if VCF0901a == 42 & year==2008 // Pennsylvania
replace battle =1 if VCF0901a == 51 & year==2008 // Virginia

replace battle = 0 if year == 2012
replace battle =1 if VCF0901a == 12 & year==2012 // Florida
replace battle =1 if VCF0901a == 37 & year==2012 // North Carolina
replace battle =1 if VCF0901a == 42 & year==2012 // Pennsylvania
replace battle =1 if VCF0901a == 39 & year==2012 // Ohio
replace battle =1 if VCF0901a == 41 & year==2012 // Virginia
replace battle =1 if VCF0901a == 19 & year==2012 // Iowa
replace battle =1 if VCF0901a == 33 & year==2012 // New Hampshire
replace battle =1 if VCF0901a == 32 & year==2012 // Nevada
replace battle =1 if VCF0901a == 55 & year==2012 // Wiscconsin

replace battle = 0 if year == 2016
replace battle =1 if VCF0901a == 4 & year==2016 // Airzona, 
replace battle =1 if VCF0901a == 12 & year==2016 // Florida
replace battle =1 if VCF0901a == 37 & year==2016 // North Carolina
replace battle =1 if VCF0901a == 42 & year==2016 // Pennsylvania
replace battle =1 if VCF0901a == 39 & year==2016 // Ohio
replace battle =1 if VCF0901a == 41 & year==2016 // Virginia
replace battle =1 if VCF0901a == 26 & year==2016 // Michigan
replace battle =1 if VCF0901a == 19 & year==2016 // Iowa
replace battle =1 if VCF0901a == 33 & year==2016 // New Hampshire
replace battle =1 if VCF0901a == 32 & year==2016 // Nevada
replace battle =1 if VCF0901a == 55 & year==2016 // Wiscconsin

gen mode = VCF0017

gen phone_live_pre = VCF0017
recode phone_live_pre (0=0) (1=1) (2=0) (3=1) (4=0)
label define phone 0 "In person" 1 "Phone" , replace
label values phone_live_pre phone  

gen internet2012 = 1 if mode==4 & year==2012
* To adjust for number of contacts
gen calls = VCF9123
gen lncalls = ln(calls)

gen date = VCF1015*-1
gen date2 = date*date
gen daysln =  VCF1015+1 
	replace daysln = ln(daysln) 
	replace daysln = (daysln+.01)*-1
	
* sum date for each year and overall
set more off
forval i = 1968(4)2016 {
 sum VCF1015	if year == `i' 
}
sum VCF1015

* Off-year
gen offyear = 1
replace offyear = 0 if year ==	1948
replace offyear = 0 if year ==	1952
replace offyear = 0 if year ==	1956
replace offyear = 0 if year ==	1960
replace offyear = 0 if year ==	1964
replace offyear = 0 if year ==	1968
replace offyear = 0 if year ==	1972
replace offyear = 0 if year ==	1976
replace offyear = 0 if year ==	1980
replace offyear = 0 if year ==	1984
replace offyear = 0 if year ==	1988
replace offyear = 0 if year ==	1992
replace offyear = 0 if year ==	1996
replace offyear = 0 if year ==	2000
replace offyear = 0 if year ==	2004
replace offyear = 0 if year ==	2008
replace offyear = 0 if year ==	2012
replace offyear = 0 if year ==	2016
drop if offyear==1

* Partisan intensity
gen pid = VCF0301
recode pid (0=.)
replace pid = . if pid==9
gen pidi = abs(pid-4) + 1

gen party = VCF0301
recode party (1=1) (2=1) (3=1) (5=0) (6=0) (7=0) (0=.) (4=.)

* party feeling thermometers
gen therm_dem = VCF0218
recode therm_dem (99=.) (98=.) (97=100)
gen therm_rep = VCF0224
recode therm_rep (99=.) (98=.) (97=100)


* candidate feeling thermometers
gen therm_dcandidate = VCF0424
recode therm_dcandidate (99=.) (98=.) (97=100)
gen therm_rcandidate = VCF0426
recode therm_rcandidate (99=.) (98=.) (97=100)

* codes in party and out party feeling thermometers
gen in_candidate = therm_dcandidate if party==1
replace in_candidate = therm_rcandidate if party==0
gen out_candidate = therm_rcandidate if party==1
replace out_candidate = therm_dcandidate if party==0

gen in_party = therm_dem if party==1
replace in_party = therm_rep if party==0
gen out_party = therm_rep if party==1
replace out_party = therm_dem if party==0




* comparison of parties and candidates
gen therm_dif_candidates = abs(therm_rc-therm_dc)
gen therm_dif_parties = abs(therm_rep-therm_dem)

gen therm_candidates = (therm_rc-therm_dc)
gen therm_parties = (therm_rep-therm_dem)

gen candidate_affective = (in_candidate - out_candidate)
gen partisan_affective = (in_party - out_party)

* Education
gen education = VCF0110
replace edu = . if educ==0




* Ideological intensity
* ideology
gen ideology = VCF0803
recode ideology (9=.) (0=.)
gen ideoi = abs(ideology-4) + 1
replace ideoi = 0 if VCF0803==9

* sorting (including reverse coding ideology)
gen i = ideology*-1
replace i = i + 8

gen sorting = abs(pid - (i)) * ideoi * pidi


* Race (African American)
* Race
gen race = VCF0105b
recode race (0=.) (9=.)
label define racelabel 1 "White" 2 "Black" 3 "Hispanic" 4 "Other" 
label values race racelabel  
*1. White non-Hispanic
*2. Black non-Hispanic
*3. Hispanic
*4. Other or multiple races, non-Hispanic
gen black = 0 if race==1
replace black = 0 if race==3
replace black = 0 if race==4
replace black = 1 if race==2
label define blacklabel 1 "Bkack" 0 "Not black" 
label values race racelabel  


* Age
gen age = VCF0101
replace age = 97 if age>97

* Sex (female)
gen female = VCF0104
replace female = . if fem ==0
replace female = . if fem ==3
replace female = fem-1
label define femalelabel 0 "Male" 1 "Female"
label values female femalelabel  

gen income = VCF0114
replace income = . if income == 0

gen south = .
replace south = 0 if VCF0112 == 1
replace south = 0 if VCF0112 == 2
replace south = 0 if VCF0112 == 4
replace south = 1 if VCF0112 == 3
label var south "South Region Dummy"
label define southern 0 "0 Non-South" 1 "1 South"
label values south southern

gen trust1 = VCF0605
recode trust1 (1=0) (2=1) (0=.) (9=.)
label define trust1label 0 "0. A few big interests" 1 "1. Benefit of all"
label values trust1 trust1label  

gen trust2 = VCF0606
recode trust2 (1=0) (2=1) (3=2) (0=.) (9=.)
label define trust2label 0 "0. A lot of waste" 1 "1. Some waste" 2 "2. Not very much waste"
label values trust2 trust2label  

gen trust1a = trust1	
su trust1a, meanonly
replace trust1a = (trust1a- r(min))/(r(max) - r(min))
gen trust2a = trust2	
su trust2a, meanonly
replace trust2a = (trust2a- r(min))/(r(max) - r(min))

gen trust = (trust1a+trust2a)/2	
	



* Knowledge
gen interviewer_assesment = VCF0050a
recode interviewer_assesment (9=.) 	(1=5) (5=1) (2=4) (4=2)

* Interest
gen interest = VCF0310
recode interest (9=.) (0=.)

* Involvement 
gen involvement= VCF0723
recode involvement (0=.)

* Married
gen married =  VCF0147 if  VCF0147 != 7
label define marriedlabel 1 "Married" 2 "Never married" 3 "Divorced" 4 "Separated" 5 "Widowed" 
label values married marriedlabel  


alpha interviewer_assesment interest involvement , gen(s)


* Models

* Balance, used to construct Figure 2
mixed VCF1015 income edu age involv i.race i.married i.VCF0112 lncalls|| year: 


* Candidate (Model 5 in Table 3)
mixed candidate_affective date income edu age involv i.race i.married i.VCF0112 calls if mode!=4|| year: c.date
outreg2 using main_result_model1_2.tex, replace ctitle(Model 5) parent(se) dec(3) alpha(.05) symbol(*)  
* Party (Model 6 in Table 3)

mixed partisan_affective date income edu age involv i.race i.married i.VCF0112 calls if mode!=4|| year: date

* In and out party ratings separately (Models 7-10 in Table 4)
mixed in_candidate  date income edu age involv i.race i.married i.VCF0112 calls if mode!=4|| year: c.date
mixed out_candidate date income edu age involv i.race i.married i.VCF0112 calls if mode!=4|| year: date

mixed in_party  date income edu age involv i.race i.married i.VCF0112 calls if mode!=4|| year: c.date
mixed out_party date income edu age involv i.race i.married i.VCF0112 calls if mode!=4|| year: date


* Robustness checks
* Main models with fixed effects
* Candidate
reg candidate_affective date income edu age involv i.race i.married i.VCF0112 calls i.year if mode!=4
outreg2 using main_result_model1_2.tex, replace ctitle(Model a) parent(se) dec(3) alpha(.05) symbol(*)  
* Party
reg partisan_affective date income edu age involv i.race i.married i.VCF0112 calls i.year if mode!=4
outreg2 using main_result_model1_2.tex, append ctitle(Model c) parent(se) dec(3) alpha(.05) symbol(*)  

* Main models with logged days
* Candidate
set more off
mixed candidate_affective daysln income edu age involv i.race i.married i.VCF0112 calls if mode!=4|| year: c.date
* Party
mixed partisan_affective daysln income edu age involv i.race i.married i.VCF0112 calls if mode!=4|| year: date

* In and out party separately
mixed in_candidate  daysln income edu age involv i.race i.married i.VCF0112 calls if mode!=4|| year: c.date
mixed out_candidate daysln income edu age involv i.race i.married i.VCF0112 calls if mode!=4|| year: date
mixed in_party  daysln income edu age involv i.race i.married i.VCF0112 calls if mode!=4|| year: c.date
mixed out_party daysln income edu age involv i.race i.married i.VCF0112 calls if mode!=4|| year: dateoutreg2 using main_result_model1_2.tex, append ctitle(Logged 19) parent(se) dec(3) alpha(.05) symbol(*)  

* Candidate with date^2
mixed candidate_affective date date2 income edu age involv i.race i.married i.VCF0112 calls if mode!=4|| year: date date2
* Party with date^2
mixed partisan_affective date date2 income edu age involv i.race i.married i.VCF0112 calls if mode!=4|| year: date date2

* In and out party ratings with date^2
mixed in_candidate  c.date##c.date income edu age involv i.race i.married i.VCF0112 calls if mode!=4|| year: c.date
mixed out_candidate c.date##c.date income edu age involv i.race i.married i.VCF0112 calls if mode!=4|| year: date
mixed in_party  c.date##c.date income edu age involv i.race i.married i.VCF0112 calls if mode!=4|| year: c.date
mixed out_party c.date##c.date income edu age involv i.race i.married i.VCF0112 calls if mode!=4|| year: date


* "Jackknife" --- exclude one election year at a time
set more off
forval i = 1980(4)2008 {
	mixed candidate_affective date income edu age involv i.race i.married i.VCF0112 calls if mode!=4 & year!=`i'|| year: c.date 
}
mixed candidate_affective date income edu age involv i.race i.married i.VCF0112 calls if mode!=4 & year != 2016|| year: c.date
 
 set more off
forval i = 1980(4)2008 {
	mixed partisan_affective date income edu age involv i.race i.married i.VCF0112 calls if mode!=4 & year!=`i'|| year: c.date 
}
mixed partisan_affective date income edu age involv i.race i.married i.VCF0112 calls if mode!=4 & year != 2016|| year: c.date



* Multilevel SUR

set more off
mixed in_candidate  date income edu age involv i.race i.married i.region ///
	calls if mode!=4|| year: c.date
mixed out_candidate date income edu age involv i.race i.married i.region ///
	calls if mode!=4|| year: date

set more off
mixed in_party  date income edu age involv i.race i.married i.region ///
	calls if mode!=4|| year: c.date
mixed out_party date income edu age involv i.race i.married i.region ///
	calls if mode!=4|| year: date
	
* multilevel SUR for candidates
set more off
# delimit ;
	gsem
	(out_candidate <- date income edu age involv i.race i.married calls i.region
		M1[year] c.date#M2[year])	
	(in_candidate <- date income edu age involv i.race i.married calls i.region
		M3[year] c.date#M4[year])
	,
	nocapslatent latent(M1 M2 M3 M4) allbaselevels covstruct(_lexogenous, diagonal) cov(e.out_candidate*e.in_candidate)
;
# delimit cr
test  _b[in_candidate:date] + _b[out_candidate:date] = 0

drop if mode==4

# delimit ;
	gsem
	(out_candidate <- date income edu age involv i.race i.married i.region calls
		M1[year] c.date#c.M2[year])	
	,
	nocapslatent latent(M1 M2) allbaselevels covstruct(_lexogenous, diagonal)
;

# delimit ;
	gsem
	(in_candidate <- date income edu age involv i.race i.married i.region calls
		M1[year] c.date#c.M2[year])	
	,
	nocapslatent latent(M1 M2) allbaselevels covstruct(_lexogenous, diagonal)
;





